class Solution:
    def GetLeastNumbers_Solution(self, t, k):
        n = len(t)
        if n==0 or n<=0 or n<k:
            return
        self.a = []
        m = self.heapSort(t)
        return m




    def heapSort(self,t):
        if t == None or len(t) < 2:
            return
        for i in range(len(t)):
            self.headInsert(t,i)
        size =len(t)-1
        self.swap(t,0,size)
        while size>0:
            self.heapIfy(t,0,size)
            size -= 1
            self.swap(t,0,size)
        return t



    def heapIfy(self,s,index,size):
        left = index * 2 + 1
        while left<size:
            if left + 1< size and s[left] < s[left+1]:
                l = left+1
            else:
                l = left
            if s[index]>s[l]:
                l = index
            else:
                l = l
            if l==index:
                break
            self.swap(s,index,l)
            index = l
            left =  index * 2 + 1



    # big
    def headInsert(self,arr,index):
        while arr[index]>arr[int((index-1)/2)]:
            arr[index],arr[int((index-1)/2)] = arr[int((index-1)/2)],arr[index]
            index = int((index-1)/2)


    def swap(self,arr,i,j):
        arr[i],arr[j] = arr[j],arr[i]


a = [4,5,1,6,2,7,3,8]
s=Solution()
print(s.GetLeastNumbers_Solution(a,4))